package vn.bang.utility;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public final class DateUtil {

	static public String getNowString(){
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		return dateFormat.format(getNow());
	}
	
	/**
	 * @return a Date object representing today.
	 */
	static public Date getNow() {
		final Calendar calendar = Calendar.getInstance();
		return calendar.getTime();
	}

	static public Date dateFormat(Date date){
		Date tmp = null;
		try{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	        //get current date time with Date()
	        tmp = dateFormat.parse(dateFormat.format(date));
		}catch(ParseException e){
			
		}
		return tmp;
	}
	
	static public Date toDate(String date){
		Date tmp = null;
		try{
			DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
	        //get current date time with Date()
	        tmp = dateFormat.parse(date);
		}catch(ParseException e){
//			JOptionPane.showMessageDialog(null,"Please input Date From!","INFORMATION",JOptionPane.WARNING_MESSAGE);
		}
		return tmp;
	}
	
	static public String toString(Date date){
		if (date == null) {
			return "";
		}
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        //get current date time with Date()
        return dateFormat.format(date);
		
	}
	/**
	 * Prevent constructor.
	 */
	private DateUtil() {
	}

}
